$(function () {
    bindDeleteEvent();
    bindConfirmDeleteEvent();
})

function bindDeleteEvent() {
    $(".btn-delete").click(function () {
        $("#deleteError").empty();
        $("#deleteModal").modal('show');
        var cid = $(this).attr("cid")
        DELETE_ID = cid;
    });
    $("#btnCancelDelete").click(function () {
        $("#deleteModal").modal('hide');
    })
}

function bindConfirmDeleteEvent() {
    $("#btnConfirmDelete").click(function () {
        $.ajax({
            url: DELETE_URL,
            type: "GET",
            data: {cid: DELETE_ID},
            dataType: "JSON",
            success: function (res) {
                if (res.status) {
                    //删除成功
                    // 1.方式一,刷新页面
                    location.reload()
                    // 2.页面不刷新
                    //$("tr[row-id='" + DELETE_ID + "']").remove()
                    //$("#deleteModal").modal('hide');
                } else {
                    $("#deleteError").text(res.detail);
                }
            }
        })
    })
}